package com.axonactive.yolo.monitor;

import com.axonactive.yolo.service.interfaces.EmailService;
import com.axonactive.yolo.service.interfaces.ExchangeRateService;
import com.axonactive.yolo.service.interfaces.FlightNotificationService;
import com.axonactive.yolo.service.interfaces.ParamLockerService;
import com.axonactive.yolo.service.interfaces.SubscribedFlightService;
import com.axonactive.yolo.service.interfaces.SubscribedFlightUserIdService;
import com.axonactive.yolo.service.interfaces.UserEmailService;
import com.axonactive.yolo.service.interfaces.UserService;
/**
 * This class provider the services that weren't autowired successfully
 * @author pqtrung
 *
 */
public class ServiceProvider {

	private static ServiceProvider instance;
	//private constructor, so i don't allow create an instance of this class explicitly
	private ServiceProvider() {
	}

	public static ServiceProvider getInstance() {
		if (instance == null) {
			instance = new ServiceProvider();
		}
		return instance;
	}
	private EmailService emailService;

	private UserService userService;

	private SubscribedFlightService subcribedFlightService;

	private SubscribedFlightUserIdService subscribedFlightUserIdService;

	private UserEmailService userEmailService;

	private FlightNotificationService flightNotificationService;

	private ParamLockerService paramLockerService;

	private ExchangeRateService exchangeRateService;

	public void injectService(Object service) {
		if (service instanceof EmailService)
		{
			emailService=(EmailService)service;
		}
		else if (service instanceof UserService){
			userService=(UserService)service;
		}
		else if (service instanceof UserEmailService){
			userEmailService=(UserEmailService)service;
		}
		else if (service instanceof SubscribedFlightService){
			subcribedFlightService=(SubscribedFlightService)service;
		}
		else if (service instanceof FlightNotificationService){
			flightNotificationService=(FlightNotificationService)service;
		}
		else if (service instanceof ParamLockerService){
			paramLockerService=(ParamLockerService)service;
		}
		else if (service instanceof SubscribedFlightUserIdService){
			subscribedFlightUserIdService=(SubscribedFlightUserIdService)service;
		}
		else if (service instanceof ExchangeRateService){
			exchangeRateService=(ExchangeRateService)service;
		}
	}

	public void rejectService(Object service){
		if (service instanceof EmailService)
		{
			emailService=null;
		}
		else if (service instanceof UserService){
			userService=null;
		}
		else if (service instanceof UserEmailService){
			userEmailService=null;
		}
		else if (service instanceof SubscribedFlightService){
			subcribedFlightService=null;
		}
		else if (service instanceof FlightNotificationService){
			flightNotificationService=null;
		}
		else if (service instanceof ParamLockerService){
			paramLockerService=null;
		}
		else if (service instanceof SubscribedFlightUserIdService){
			subscribedFlightUserIdService=null;
		}
		else if (service instanceof ExchangeRateService){
			exchangeRateService=null;
		}
	}

	public Object getService(Object serviceType)
	{
		if (serviceType.equals(EmailService.class)){
			return this.emailService;
		}
		else if (serviceType.equals(UserService.class)){
			return this.userService;
		}
		else if (serviceType.equals(UserEmailService.class)){
			return this.userEmailService;
		}
		else if (serviceType.equals(SubscribedFlightService.class)){
			return this.subcribedFlightService;
		}
		else if (serviceType.equals(FlightNotificationService.class)){
			return this.flightNotificationService;
		}
		else if (serviceType.equals(ParamLockerService.class)){
			return this.paramLockerService;
		}
		else if (serviceType.equals(SubscribedFlightUserIdService.class)){
			return this.subscribedFlightUserIdService;
		}
		else if (serviceType.equals(ExchangeRateService.class)){
			return this.exchangeRateService;
		}
		return null;
	}



}
